package cn.edu.hhtc.stsystem.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.springframework.stereotype.Repository;

import cn.edu.hhtc.hibernate.utils.HibernateDao;
import cn.edu.hhtc.stsystem.entity.PrimaryMaterialEntity;
import cn.edu.hhtc.stsystem.entity.form.PrimaryMaterialEntityForm;

@Repository
public class PrimaryMaterialDao extends HibernateDao<PrimaryMaterialEntity, Long> {
	
	
    public List<PrimaryMaterialEntity> find(PrimaryMaterialEntityForm form){
    	StringBuffer hql = new StringBuffer("select new PrimaryMaterialEntity(t1,t2.supplierName) from PrimaryMaterialEntity t1, SupplierEntity t2  where t1.pmSuId=t2.supplierId");
    	List<Object> params = new ArrayList<Object>();
    	String pmName=form.getPmName();
    	String supplierName=form.getSupplierName();
    	if(StringUtils.isNotBlank(pmName)){
    		hql.append(" and t1.pmName=?");
    		params.add(pmName);
    	}
    	if (StringUtils.isNotBlank(supplierName)) {
    		hql.append(" and t2.supplierName=?");
    		params.add(supplierName);
    	}
    	List<PrimaryMaterialEntity> list=super.createQuery(hql.toString(), params.toArray()).list();
    	return list;
    }
}
